import java.util.Scanner;

public class coinsToPoint {
    // 定义硬币面值和数量的映射关系
    public static void main(String[] args) {
        int[] coins = {100, 50, 10, 5, 1}; // 硬币面值，单位为分
        int[] counts = {4, 8, 20, 4, 20}; // 对应硬币数量
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要找零的金额（单位：元）：");
        double amount = scanner.nextDouble();

        int targetAmount = (int) (amount * 100); // 将金额转换为以分为单位的整数
        int[] change = getChange(coins, counts, targetAmount);
        System.out.println("找零的分配方法为：");
        for (int i = 0; i < coins.length; i++) {
            System.out.println(coins[i] / 100.0 + "元：" + change[i] + "个");
        }
    }

    public static int[] getChange(int[] coins, int[] counts, int targetAmount) {
        int[] change = new int[coins.length]; // 存储找零的硬币数量
        int remainingAmount = targetAmount; // 剩余需要找零的金额

        for (int i = 0; i < coins.length; i++) {
            int coin = coins[i];
            int count = counts[i];
            int num = Math.min(remainingAmount / coin, count); // 当前面值硬币最多可用数量
            change[i] = num; // 记录使用的硬币数量
            remainingAmount -= num * coin; // 更新剩余需要找零的金额
        }
        return change;
    }
}
